package com.example.shop.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.shop.persistence.entity.UserAddress;
import com.example.shop.persistence.mapper.UserAddressMapper;
import com.example.shop.modules.sys.service.IUserAddressService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户收货地址表 服务实现类
 * </p>
 *
 * @author jason
 * @since 2019-12-17
 */
@Service
public class UserAddressServiceImpl extends ServiceImpl<UserAddressMapper, UserAddress> implements IUserAddressService {

    @Autowired
    private UserAddressMapper userAddressMapper;

    //修改默认地址
    public void editIsDefault(Integer userID){
        QueryWrapper qw = new QueryWrapper();
        qw.eq("userID", userID);
        // 先查出目标userID 的所有收货地址
        List<UserAddress> list = userAddressMapper.selectList(qw);
        // 循环实体对象集合
        for(UserAddress userAddress1: list){
            // 将是否默认  改为否
            userAddress1.setIsDefault(0);
            // 将改变后的实体对象集合存入数据库
            userAddressMapper.updateById(userAddress1);
        }
    }
}
